import { request } from './request';

// 获取所有的角色列表数据
export function getRolesList() {
  return request({
    method: 'GET',
    url: 'roles',
  });
}

// 删除角色指定权限
export function removeRoleRight(role, rightId) {
  return request({
    method: 'delete',
    url: `roles/${role.id}/rights/${rightId}`,
  });
}

// 添加角色
export function addRoles(addRoleForm) {
  return request({
    method: 'POST',
    url: `roles`,
    data: {
      roleName: addRoleForm.roleName,
      roleDesc: addRoleForm.roleDesc,
    },
  });
}

// 根据 ID 查询角色信息
export function queryRoleInfo(id) {
  return request({
    method: 'get',
    url: `roles/${id}`,
  });
}

// 根据id编辑提交角色
export function editRoleSub(addRoleForm) {
  return request({
    method: 'put',
    url: `roles/${addRoleForm.roleId}`,
    data: {
      roleName: addRoleForm.roleName,
      roleDesc: addRoleForm.roleDesc,
    },
  });
}

// 根据ID删除提交角色
export function removeRoleSub(id) {
  return request({
    method: 'delete',
    url: `roles/${id}`,
  });
}

// 角色授权
export function roleRights(roleId, rids) {
  return request({
    method: 'post',
    url: `roles/${roleId}/rights`,
    data: {
      rids: rids,
    },
  });
}
